package com.weatherinczbackend;

import com.weatherinczbackend.exceptions.InternalErrorException;

/**
 * Class with static methods which are helpful with code.
 * 
 * @author Bc. Michal Stava 255739 <255739@mail.muni.cz>
 */
public class Utils {
   
  /**
   * Copy one two dimensional array of strings to new one and return it.
   * 
   * @param arrayToCopyFrom not null two dimensional string array
   * @return new not null two dimensional string array like copy of the arrayToCopyFrom
   * @throws InternalErrorException if arrayToCopyFrom is null or has 0 length
   */  
  public static String[][] copyTwoDimensionalArrayOfStrings(String[][] arrayToCopyFrom) throws InternalErrorException {
    if(arrayToCopyFrom == null) throw new InternalErrorException("Array to copy can't be null");
    if(arrayToCopyFrom.length == 0) throw new InternalErrorException("Can't copy array with 0 legth.");
    
    String[][] newArray = new String[arrayToCopyFrom.length][arrayToCopyFrom[0].length];
    
    for(int i=0; i<arrayToCopyFrom.length; i++)
      for(int j=0; j<arrayToCopyFrom[i].length; j++)
        newArray[i][j]=arrayToCopyFrom[i][j];
    return newArray;
  }
}
